//
//  ViewController.swift
//  ReviewSwift
//
//  Created by ladystyle100 on 2017/8/23.
//  Copyright © 2017年 WangXQ. All rights reserved.
//


/** 先来看系统创建的一个类 */

// 导入类(一般在工程内创建的文件都不用导入, 但用Cocoapods和Carthage就得import进来)
import UIKit

/** class 类名: 继承, 协议...... */
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    
    /** override(重新父类标志) func(表示函数) 函数名 */
    override func viewDidLoad() {
        /** 父类调用 */
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        
        // 首先做一个优良传统的开头, 每一个程序都先 Hello world
        print("Hello world")
        
        self.initData()
        self.view.addSubview(self.tableView)
    }
    
    
    /** 和OC一样, 收到内存告警 */
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    /*
     // MARK: - Navigation
     
     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     // Get the new view controller using segue.destinationViewController.
     // Pass the selected object to the new view controller.
     }
     */
    
    let reusing = "VCCell"
    
    private var dataArr = [String]()
    
    private lazy var tableView: UITableView = {
        let xqTableView: UITableView = UITableView.init(frame: CGRect.init(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height - 64), style: .plain)
        xqTableView.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: self.reusing)
        xqTableView.delegate = self
        xqTableView.dataSource = self
        xqTableView.tableFooterView = UIView()
        
        return xqTableView
    }()
    
    private func initData() {
        self.dataArr.append(contentsOf: ["Struct", "Function", "闭包Block", "Protocol", "Pointer"])
        
    }
    
    /** UITableViewDataSource */
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataArr.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: reusing, for: indexPath)
        
        cell.textLabel?.text = self.dataArr[indexPath.row]
        
        return cell
    }
    
    /** UITableViewDelegate */
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        var vc: UIViewController?
        switch indexPath.row {
        case 0:
            vc = StructVC()
            
        case 1:
            vc = FunctionVC()
            
        case 2:
            vc = ClosureVC()
            
        case 3:
            vc = ProtocolVC()
            
        case 4:
            vc = PointerVC()
            
        default:
            vc = StructVC()
        }
        
        self.navigationController?.pushViewController(vc!, animated: true)
        
        tableView.reloadRows(at: [indexPath], with: .fade)
    }
    
    
    
}














